<template>
  <div class="playList-detail">
    <div class="pic">
      <van-icon name="arrow-left" @click="goBack()" />
      <!-- <img :src="picUrl" alt /> -->
      <van-image :src="picUrl" fit="cover" />
    </div>
    <div v-if="songUrl == ''" class="play">
      <div>
        <van-icon name="play-circle-o" @click="selectSong(firstItem)" />
        <span>播放全部</span>
      </div>
      <div>
        <van-icon name="like-o"></van-icon>
        <span>收藏歌单</span>
      </div>
    </div>
    <div v-else>
      <audio :src="songUrl" autoplay controls></audio>
    </div>
    <div class="song-list">
      <ul>
        <li
          v-for="item in songList"
          :key="item.songid"
          @click="selectSong(item)"
        >
          <h4>{{ item.songname }}</h4>
          <span>{{ item.singer[0].name }}-{{ item.albumname }}</span>
        </li>
      </ul>
    </div>
  </div>
</template>
<script>
import axios from "axios";
export default {
  data() {
    return {
      songList: {},
      picUrl: "",
      songUrl: "",
      firstItem: "",
    };
  },
  created() {
    // console.log(this.$route.params.id);
    this.getData();
  },
  methods: {
    getData() {
      axios
        .get("/api/songlist", {
          params: {
            id: this.$route.params.id,
          },
        })
        .then((res) => {
          console.log(res.data);
          this.songList = res.data.data.songlist;
          this.picUrl = res.data.data.logo;
          this.firstItem = this.songList[0];
        })
        .catch((err) => {
          console.error(err);
        });
    },
    goBack() {
      this.$router.go(-1);
    },
    selectSong(item) {
      axios
        .get("/jsososo/song/urls", {
          params: {
            id: item.songmid,
          },
        })
        .then((res) => {
          console.log(res.data.data[item.songmid]);
          this.songUrl = res.data.data[item.songmid];
        })
        .catch((err) => {
          console.error(err);
        });
    },
  },
};
</script>
<style scoped>
.song-list > ul > li {
  text-align: left;
  margin-left: 20px;
}
.song-list > ul > li > span {
  color: rgb(172, 172, 172);
  font-size: 10px;
}
.song-list > ul > li > h4 {
  margin-bottom: 0;
}

.pic {
  height: 275px;
}
.van-image {
  height: 275px;
  width: 100%;
}
.van-icon {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 999;
  font-size: 40px;
}
.play {
  padding: 1rem;
  position: relative;
  overflow: hidden;
}
.play > div:nth-of-type(1) {
  float: left;
}
.play > div:nth-of-type(2) {
  float: right;
}
.play > div > span {
  display: block;
  font-size: 12px;
}
.van-icon-like-o {
  font-size: 22px;
  position: relative;
}
.van-icon-play-circle-o {
  position: relative;
}
</style>
